﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace SimplexEngine
{
    public class StaticMeshEntity : Entity
    {
        public StaticMeshEntity(String scene_object_name, String mesh_name) : base(scene_object_name)
        {
            Resource static_mesh = Root.Instance.ContentSystem.GetResource(mesh_name);
            static_mesh_instance = StaticMesh.CreateStaticMeshInstance(static_mesh);
        }

        protected override void OnDraw(GameTime game_time, Int64 frame_number)
        {
            List<RenderElement> render_elements = static_mesh_instance.CreateRenderElements(this);

            foreach (RenderElement render_element in render_elements)
                Root.Instance.RenderSystem.AddToRenderList(render_element);

        }

        protected StaticMeshInstance static_mesh_instance = null;
    }

    public class StaticMeshEntityFactory : SceneObjectFactory
    {
        public override string Type
        {
            get { return "STATICMESHENTITY"; }
        }

        public override SceneObject CreateSceneObject(String name, Dictionary<String, String> parameters)
        {
            return new StaticMeshEntity(name, parameters["MeshName"]);
        }
    }
}
